﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BuildPlannerLib.Buildings;

namespace BuildPlannerLib
{
    public class Player
    {
        // Resource fields for non-race-specific resources
        public Resource Minerals;
        public Resource Gas;
        public Resource Supply;
        public ResourceWithMaximum SupplyMaximum;

        // Integer property for the amount of supply that is finished or in-production
        private int supplyInProduction;
        public int SupplyInProduction
        {
            get { return supplyInProduction; }
            set { supplyInProduction = value; }
        }

        // Integer property for idle (unassigned) workers
        private int idleWorkers;
        public int IdleWorkers
        {
            get { return idleWorkers; }
            set { idleWorkers = value; }
        }

        // MainBuilding field for the main building of the player race
        public MainBuilding MainBuilding;

        // List fields for each Building, Unit, Upgrade, and LevelUpgrade to be filled by the Race-specific derived class
        public List<Building> Buildings;
        public List<Unit> Units;
        public List<Upgrade> Upgrades;
        public List<LevelUpgrade> LevelUpgrades;

        public Player()
        {
            Minerals = new Resource(50);
            Gas = new Resource();
            Supply = new Resource(6);

            Buildings = new List<Building>();
            Units = new List<Unit>();
            Upgrades = new List<Upgrade>();
            LevelUpgrades = new List<LevelUpgrade>();
        }

        // Resets all variables to their starting values
        public virtual void Reset()
        {
            Minerals.Set(50);
            Gas.Set(0);
            Supply.Set(6);

            IdleWorkers = 0;

            MainBuilding.Reset();

            foreach (Building b in Buildings)
                b.Reset();

            foreach (Unit u in Units)
                u.Count = 0;

            foreach (Upgrade u in Upgrades)
                u.Reset();

            foreach (LevelUpgrade u in LevelUpgrades)
                u.Reset();
        }

        public Building GetBuilding(string name)
        {
            Building building = Buildings.Find(delegate(Building b) { return b.Name == name; });
            return building;
        }
    }
}
